<!-- confirm 确认对话框 组件 -->

<template>
  <transition name="dialog-fade">
    <div class="my-dialog"
         v-show="showFlag"
         @click.stop>
      <div class="dialog-wrapper">
        <div class="dialog-content">
          <p class="text">{{ text }}</p>

          <div class="operate">
            <div @click="confirm"
                 class="operate-btn left">{{ confirmBtnText }}</div>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
export default {
  components: {},
  data () {
    return {
      // 显示
      showFlag: false
    }
  },
  props: {
    // 描述性文字
    text: {
      type: String,
      default: '提示框内容'
    },
    confirmBtnText: {
      type: String,
      default: '确定'
    }
  },
  watch: {},
  methods: {
    // 对外提供，显示对话框
    show () {
      this.showFlag = true
    },
    // 对外提供，隐藏对话框
    hide () {
      this.showFlag = false
    },
    confirm () {
      this.showFlag = false
      this.$emit('confirm')
    }
  },
  // 过滤器设计目的就是用于简单的文本转换
  filters: {},
  // 若要实现更复杂的数据变换，你应该使用计算属性
  computed: {},
  created () { },
  mounted () { },
  destroyed () { }
}
</script>

<style lang="scss" scoped>
@import "@/assets/scss/base.scss";

.my-dialog {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 998;
  background-color: rgba(0, 0, 0, 0.3);
  &.dialog-fade-enter-active {
    animation: confirm-fadein 0.3s;
    .dialog-content {
      animation: confirm-zoom 0.3s;
    }
  }
  .dialog-wrapper {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 999;
    .dialog-content {
      width: 270px;
      border-radius: 13px;
      background: #fff;
      .text {
        padding: 19px 15px;
        line-height: 22px;
        text-align: center;
        font-size: 16px;
        color: $lightgrey;
      }
      .operate {
        display: flex;
        align-items: center;
        text-align: center;
        font-size: 16px;
        .operate-btn {
          flex: 1;
          line-height: 22px;
          padding: 10px 0;
          position: relative;
          &:after {
            @include setTopLine();
          }
          // border-top: 1px solid $bordercolor;
          color: $lightgrey;
          // &.left {
          //   border-right: 1px solid $bordercolor;
          // }
        }
      }
    }
  }
}

@keyframes confirm-fadein {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

@keyframes confirm-zoom {
  0% {
    transform: scale(0);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}
</style>
